package com.store.controller;

import com.store.domain.R;
import com.store.domain.dto.UpdatePasswordDto;
import com.store.domain.entity.User;
import com.store.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author yu
 * @date 2024/6/26
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Resource
    private UserService userService;
    @PostMapping("login")
    public R login(@RequestBody User user){
        user.setRoleId(2);
        return userService.login(user);
    }
    @PostMapping("register")
    public R register(@RequestBody User user){
        return userService.register(user);
    }
    @GetMapping("getUserInfo")
    public R getUserInfo(){
        return userService.getUserInfo();
    }
    @PostMapping("logout")
    public R logout(){
        return userService.logout();
    }
    @PutMapping("updateUser")
    public R updateUser(@RequestBody User user){
        return userService.updateUserInfo(user);
    }
    @PutMapping("updatePassword")
    public R updatePassword(@RequestBody UpdatePasswordDto updatePasswordDto){
        return userService.updatePassword(updatePasswordDto);
    }
}
